package com.ruoyi.web.controller.barcode;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BarcodeDoctypeMapping;
import com.ruoyi.system.service.IBarcodeDoctypeMappingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 单据类型映射Controller
 * 
 * @author ruoyi
 * @date 2025-03-27
 */
@RestController
@RequestMapping("/barcode/doctype")
public class BarcodeDoctypeMappingController extends BaseController
{
    @Autowired
    private IBarcodeDoctypeMappingService barcodeDoctypeMappingService;

    /**
     * 查询单据类型映射列表
     */
    @PreAuthorize("@ss.hasPermi('barcode:doctype:list')")
    @GetMapping("/list")
    public TableDataInfo list(BarcodeDoctypeMapping barcodeDoctypeMapping)
    {
        startPage();
        List<BarcodeDoctypeMapping> list = barcodeDoctypeMappingService.selectBarcodeDoctypeMappingList(barcodeDoctypeMapping);
        return getDataTable(list);
    }

    /**
     * 导出单据类型映射列表
     */
    @PreAuthorize("@ss.hasPermi('barcode:doctype:export')")
    @Log(title = "单据类型映射", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BarcodeDoctypeMapping barcodeDoctypeMapping)
    {
        List<BarcodeDoctypeMapping> list = barcodeDoctypeMappingService.selectBarcodeDoctypeMappingList(barcodeDoctypeMapping);
        ExcelUtil<BarcodeDoctypeMapping> util = new ExcelUtil<BarcodeDoctypeMapping>(BarcodeDoctypeMapping.class);
        util.exportExcel(response, list, "单据类型映射数据");
    }

    /**
     * 获取单据类型映射详细信息
     */
    @PreAuthorize("@ss.hasPermi('barcode:doctype:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(barcodeDoctypeMappingService.selectBarcodeDoctypeMappingById(id));
    }

    /**
     * 新增单据类型映射
     */
    @PreAuthorize("@ss.hasPermi('barcode:doctype:add')")
    @Log(title = "单据类型映射", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BarcodeDoctypeMapping barcodeDoctypeMapping)
    {
        barcodeDoctypeMapping.setCreatedBy(getUsername());
        barcodeDoctypeMapping.setCreatedDate(new Date());
        return toAjax(barcodeDoctypeMappingService.insertBarcodeDoctypeMapping(barcodeDoctypeMapping));
    }

    /**
     * 修改单据类型映射
     */
    @PreAuthorize("@ss.hasPermi('barcode:doctype:edit')")
    @Log(title = "单据类型映射", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BarcodeDoctypeMapping barcodeDoctypeMapping)
    {
        barcodeDoctypeMapping.setModifiedBy(getUsername());
        barcodeDoctypeMapping.setModifiedDate(new Date());
        return toAjax(barcodeDoctypeMappingService.updateBarcodeDoctypeMapping(barcodeDoctypeMapping));
    }

    /**
     * 删除单据类型映射
     */
    @PreAuthorize("@ss.hasPermi('barcode:doctype:remove')")
    @Log(title = "单据类型映射", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(barcodeDoctypeMappingService.deleteBarcodeDoctypeMappingByIds(ids));
    }
}
